      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
        <ul class="nav nav-tabs mytabs">
  		  	 <li  class="active"><a href="<?=site_url()?>/order/index">订单列表</a></li>
  		  </ul>
      <div class="" style="padding-bottom:20px;min-width:1055px;">
        <div class="input-group fl">
  		  	<select id="state"  class="form-control" style="width:100px;">
          	<option value="-1"<?php if($state ==-1) echo "selected"; ?>>所 有</option>
          	<option value="0" <?php if($state ==0) echo "selected"; ?>>待确认</option>
          	<option value="1" <?php if($state ==1) echo "selected"; ?>>待配送</option>
          	<option value="2" <?php if($state ==2) echo "selected"; ?>>已完成</option>
          </select>
          <input type="text" name="phone" id="phone" placeholder="请输入手机号" style="width:120px;">
          <button class="btn btn-primary" id="searchuser">搜 索</button>
  		  </div>

  		  <div class="btn-group" style="padding-left:6px;">

          <div class="fl">
            <input type="text" class="fl" id="sdate" name="sdate" value="<?php echo $start; ?>" style="width:100px;">
            <span style="" class="input-group-span"> 至 </span>
            <input type="text" id="edate" name="edate" value="<?php echo $end; ?>" class="fl" style="width:100px;">
          </div>

          <button style="margin-left:5px;" class="btn btn-primary" id="order_count">导出订单统计</button>
          <button class="btn btn-primary" id="order_print">打印</button>

          <button style="margin-left:5px;" class="btn btn-primary" id="order_count_2">导出学生订餐</button>
          <button class="btn btn-primary" id="order_print_2">打印</button>
          <!--
          <button class="btn btn-primary" id="order_send">导出配送单</button>-->
        </div>

        <div class="btn-group">
        	<!--
        	<button class="btn btn-primary" id="order_remind">短信提醒</button>
        	<button class="btn btn-primary" id="order_check">一键确认</button>
        	<button class="btn btn-primary" id="order_finish">一键完成</button>-->
        	<button class="btn btn-danger" id="order_stop" style="display:<?php if($orderstate==1){echo 'none';}?>">关闭下单</button>
        	<button class="btn btn-success" id="order_start" style="display:<?php if($orderstate==0){echo 'none';}?>">开启下单</button>
        </div>
      </div>


          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>订单编号</th>
                      <th>订单状态</th>
                      <th>下单时间</th>
                      <th>学生姓名</th>
                      <th>家长姓名</th>
                      <th>手机号</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($orders as $item):?>
                    <tr>
                      <td><?php echo $item['id'];?></td>

                      <td><?php echo $item['orderno'];?></td>
                      <td>
                      	<?php
                      	if($item['state'] == 0)
                        {
                        	echo '待确认';
						}
						 if($item['state'] == 1)
                        {
                        	echo '待收货';
						}
						 if($item['state'] == 2)
                        {
                        	echo '已完成';
						}
					  ?>
                        <?php if($item['del']==1){?>
                         <font color="red">&nbsp;(已删除)</font>
                        <?php }?>
                      </td>
                      <td><?php echo $item['order_time'];?></td>
                      <td><?php echo $item['sname'];?></td>
                      <td><?php echo $item['pname'];?></td>
                      <td><?php echo $item['phone'];?></td>
                      <td>
                         <a href="<?php echo site_url('order/detail/id/'.$item['id'])?>" class="detail">订单详情</a>
                         | <a href="#" class="del" data-id="<?php echo $item['id'];?>">删除</a>
                      </td>
                    </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div><div class="pagination" style="margin-bottom:20px;">
               <?php  echo $links; ?></div>
            </div>
          </div>
        </div>
      </div>
   <script>
	$(document).ready(function() {
		$('#sdate').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
		$('#edate').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
		$("#submit_btn").click(function() {
			var state = $("#state").val();
			var url = "<?php echo site_url('order/index')?>";
			window.location.href=url+"/state/"+state;
		});
    // 订单统计
		$("#order_count").click(function() {
			var sdate = $("#sdate").val();
			var edate = $("#edate").val();
			var url = "<?php echo site_url('order/exportNewOrders')?>";
			window.location.href=url+"/sdate/"+sdate+"/edate/"+edate;
		});
    $("#order_count_2").click(function() {
			var sdate = $("#sdate").val();
			var edate = $("#edate").val();
			var url = "<?php echo site_url('order/exportUserOrders2')?>";
			window.location.href=url+"/sdate/"+sdate+"/edate/"+edate;
		});
    $("#order_print").click(function() {
			var sdate = $("#sdate").val();
			var edate = $("#edate").val();
			var url = "<?php echo site_url('order/export')?>";
			window.location.href=url+"/sdate/"+sdate+"/edate/"+edate;
		});
    $("#order_print_2").click(function() {
			var sdate = $("#sdate").val();
			var edate = $("#edate").val();
			var url = "<?php echo site_url('order/export2')?>";
			window.location.href=url+"/sdate/"+sdate+"/edate/"+edate;
		});
		$("#order_send").click(function() {
			var sdate = $("#sdate").val();
			var edate = $("#edate").val();
			var url = "<?php echo site_url('order/exportOrderdetails')?>";
			window.location.href=url+"/sdate/"+sdate+"/edate/"+edate;
		});
		$("#order_check").click(function() {
			if(confirm("确定一键确认订单吗？"))
			{
			$.ajax({
				url : '<?php echo site_url('order/oneclick')?>',
				type : "post",
				async : true,
				data : {
					'state':1
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$("#order_finish").click(function() {
			if(confirm("确定一键完成订单吗？"))
			{
			$.ajax({
				url : '<?php echo site_url('order/oneclick')?>',
				type : "post",
				async : true,
				data : {
					'state':2
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".del").click(function() {
			if(confirm("确定要删除该订单吗？"))
			{
				var id = $(this).attr("data-id");
				$.ajax({
					url : '<?php echo site_url('order/delete')?>',
					type : "post",
					async : false,
					data : {
						'id' : id
					},
					dataType : "json",
					success : function(data) {
						if(data.code)
						{
							alert(data.msg);
							window.location.reload();
						}else{
							alert(data.msg);
						}
					}
				});
			}
		});

    $(".rec").click(function() {
      if(confirm("确定要恢复该订单吗？"))
      {
        var id = $(this).attr("data-id");
        $.ajax({
          url : '<?php echo site_url('order/recover')?>',
          type : "post",
          async : false,
          data : {
            'id' : id
          },
          dataType : "json",
          success : function(data) {
            if(data.code)
            {
              alert(data.msg);
              window.location.reload();
            }else{
              alert(data.msg);
            }
          }
        });
      }
    });
	});

      $('body').on('click', '#searchuser', function(){
      	window.location.href = '<?=site_url('order/index')?>'+ '/state/' + $('#state').val() +'/phone/' + $('#phone').val();
      })


      //短信提醒
      var remind_flag = false;
      $('body').on('click', '#order_remind', function(){

      	if(remind_flag){
      		return;
      	}

      	remind_flag = true;
      	$(this).text('正在处理');
      	var _this = $(this);
      	$.ajax({
      		url: '<?=site_url("/order/remind")?>',
      		type: 'post',
      		data: {},
      		success: function(d){
      			remind_flag = false;
      			_this.text('短信提醒');

      			alert(d.msg)
      		},
      		error: function(){

      		},
      		dataType: 'json'
      	})
      })

      //关闭下单
      $('body').on('click', '#order_stop', function(){
      	if(!confirm('确定要关闭下单吗')){
      		return;
      	}

      	$.ajax({
      		url: '<?=site_url("/order/setOrderstate")?>',
      		type: 'post',
      		data: {
      			state: 1
      		},
      		success: function(d){
      			$('#order_start').css('display', 'inline');
      			$('#order_stop').css('display', 'none');
      		},
      		error: function(){

      		},
      		dataType: 'json'
      	})
      })

      //开启下单
      $('body').on('click', '#order_start', function(){
      	if(!confirm('确定要开启下单吗')){
      		return;
      	}
      	$.ajax({
      		url: '<?=site_url("/order/setOrderstate")?>',
      		type: 'post',
      		data: {
      			state: 0
      		},
      		success: function(d){
      			$('#order_start').css('display', 'none');
      			$('#order_stop').css('display', 'inline');
      		},
      		error: function(){

      		},
      		dataType: 'json'
      	})
      })
</script>
